import request from '@/utils/request/req';

// 部门信息接口
export interface Department {
  deptId: number | string;
  parentId: number;
  parentName: string | null;
  ancestors: string;
  deptName: string;
  orderNum: number | string;
  leader: string;
  phone: string;
  email: string;
  status: string;
  createTime: string;
  children?: Department[];
}

// 新增部门请求参数
export interface AddDeptParams {
  parentId: number;
  deptName: string;
  orderNum: string;
  leader: string;
  phone: string;
  email: string;
}

// 编辑部门请求参数
export interface EditDeptParams extends AddDeptParams {
  deptId: number | string;
}

// 部门列表响应
export type DeptListResponse = Department[];

// 新增部门
export function addDepartment(data: AddDeptParams) {
  return request({
    url: '/enterprise/addDept',
    method: 'post',
    data
  });
}

// 编辑部门
export function editDepartment(data: EditDeptParams) {
  return request({
    url: '/enterprise/editDept',
    method: 'post',
    data
  });
}

// 删除部门
export function deleteDepartment(deptId: number | string) {
  return request({
    url: `/enterprise/deleteDept/${deptId}`,
    method: 'post'
  });
}

// 获取部门列表
export function getDepartmentList(params?: { deptName?: string; status?: string }) {
  return request<DeptListResponse>({
    url: '/enterprise/deptList',
    method: 'get',
    params
  });
}
